<template>
  <a-modal
    title="操作"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
  >


    <a-spin :spinning="confirmLoading">
      <a-form :form="form">


        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="积分">
          <a-input-number style="width: 100%" :min="0"  placeholder="请输入需减少的积分" v-decorator="[ 'totalFee', {rules: [{ required: true, message: '请输入积分' }]}]"
          ></a-input-number>
        </a-form-item>

        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="备注">
          <a-textarea placeholder="备注" v-decorator="[ 'remark', {rules: [{ required: true, message: '请输入备注' }]}]"
          ></a-textarea>
        </a-form-item>

      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { save } from '../../../api/business/member'
  import ATextarea from 'ant-design-vue/es/input/TextArea'

  export default {
    components: { ATextarea },
    //--############  data() ###############-->
    data() {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },
        visible: false,
        confirmLoading: false,
        mdl: {},
        form: this.$form.createForm(this),

        isDisabled: false,
        openid: ''
      }
    },
    //--############  data() ###############-->

    created() {
    },

    //--############  methods() ###############-->
    methods: {
      edit(record) {
        this.isDisabled = true
        this.mdl = Object.assign({}, record)
        this.visible = true
        this.openid = record.openid
      },
      close() {
        this.$emit('close')
        this.visible = false
        this.form.resetFields()
        this.mdl = {}
      },
      handleOk() {
        const _this = this
        // 触发表单验证
        this.form.validateFields((err, values) => {
          // 验证表单没错误
          if (!err) {
            // values.id = this.mdl.id
            values.openId = _this.openid;
            _this.confirmLoading = true

            console.log(values)
            save(values).then((res) => {
              if (res.code === 200) {
                _this.$message.success('保存成功')
                _this.$emit('ok')
                _this.close()
              } else {
                this.$notification.error({
                  message: '错误',
                  description: res.message,
                  duration: 4
                })
              }
            }).catch(() => {
              // Do something
            }).finally(() => {
              _this.confirmLoading = false
            })
          }
        })
      },
      handleCancel() {
        this.close()
      }
    }
    //--############  methods() ###############-->
  }
</script>

<style scoped>

</style>
